package com.cdream.basic.algorithm.leetcode.linkedlist;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author cdream
 * @date 8/1/21
 */
public class Question1337 {
    public int[] kWeakestRows(int[][] mat, int k) {
        PriorityQueue<int[]> p = new PriorityQueue<>(k,
                Comparator.<int[]>comparingInt(a -> a[1]).thenComparingInt(b->b[0]));
        for (int i = 0; i < mat.length; i++) {
            int sum = Arrays.stream(mat[i]).sum();
            p.offer(new int[]{sum, i});
        }
        int[] res = new int[k];
        for (int i = 0; i < res.length; i++) {
            res[i] = p.poll()[1];
        }
        return res;
    }

    public static void main(String[] args) {
    }
}
